﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class SettlementCell : MonoBehaviour {

	// Use this for initialization
	public long PlayerId;
	public Image headImg;
	private Image Owner;
	private Text nameTxt;
	private Text idTxt;
	private Text CardTypeTxt;
	private Text MarkTxt;

	public Sprite head ;
	public string Name = "";
	public string CardType = "";
	public string Mark = "0";
	public string happy = "0";
	public List<int> list;


	void Start () {
		InvokeRepeating ("init", 0.1f, 0f);
	}

	private void init(){
		if(PlayerId == info.UserInfo.UserData.id){
			transform.GetChild (1).gameObject.SetActive (false);
		}

		if(PlayerId == 0 ){
			return;
		}

		headImg = transform.GetChild (2).GetComponent<Image> ();
		headImg.transform.GetChild(0).GetComponent<Image>().sprite = head;
		nameTxt = transform.GetChild (3).GetComponent<Text> ();
		idTxt = transform.GetChild (4).GetComponent<Text> ();
		CardTypeTxt = transform.GetChild (5).GetComponent<Text> ();
		MarkTxt = transform.GetChild (10).GetComponent<Text> ();
		Owner = transform.GetChild (12).GetComponent<Image> ();
		ChangeStyle(ZJHCards.CheckCard(list[0]),transform.GetChild (6).GetComponent<Image> ());
		ChangeStyle(ZJHCards.CheckCard(list[1]),transform.GetChild (7).GetComponent<Image> ());
		ChangeStyle(ZJHCards.CheckCard(list[2]),transform.GetChild (8).GetComponent<Image> ());

		nameTxt.text = Name;
		if (int.Parse (Mark) < 0) {
			MarkTxt.color = Color.green;
		}
		MarkTxt.text += Mark.ToString();


		if (int.Parse (Mark) < 0) {
			transform.GetChild (9).gameObject.SetActive (false);
		} 

		idTxt.text = "ID:"+ PlayerId.ToString ();
	
		if(CardType == "0"){
			//CardTypeTxt.text = "钳子";
		}else if(CardType == "1"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/散牌",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
		
		}else if(CardType == "2"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/对子",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
		}else if(CardType == "3"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/顺子",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
		}else if(CardType == "4"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/金花",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
			CardTypeTxt.text = "金花";
		}else if(CardType == "5"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/顺金",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
		}else if(CardType == "6"){
			Sprite texture = (Sprite)Resources.Load("image/ZJH/Txt/豹子",typeof(Sprite));
			CardTypeTxt.transform.GetChild(0).GetComponent<Image>().sprite = texture;
		}

		if( happy != "0" ){
			if (int.Parse (happy) > 0) {
				transform.GetChild (11).GetComponent<Text> ().text = "(喜+" + happy + ")";
			} else {
				transform.GetChild (11).GetComponent<Text> ().text = "(喜" + happy + ")";
			}
		}

		if (info.UserInfo.room.owner != PlayerId) {
			Owner.gameObject.SetActive (false);
		}
	}



	private void ChangeStyle(string str,Image img){
		Sprite texture = (Sprite)Resources.Load("image/Poker/"+str,typeof(Sprite));
		img.sprite = texture;

	}
	
	// Update is called once per frame
	void Update () {

	}
}
